package com.paireach.szwolaiyun.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.paireach.szwolaiyun.R;
import com.paireach.szwolaiyun.activity.ChangePasswordActivity;
import com.paireach.szwolaiyun.activity.LoginActivity;
import com.paireach.szwolaiyun.sz_common_widget.fragment.BaseFragment;
import com.paireach.szwolaiyun.sz_util.SharedPreferencesUtil;

import java.util.Set;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

public class PersonalCenterFragment extends BaseFragment implements View.OnClickListener {

    private View view;
    private Button logout;
    private RelativeLayout rl_changepsw;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_personal_center, null);
        initControl();
        return view;
    }

    private void initControl() {
        logout = (Button) view.findViewById(R.id.bt_logout);
        rl_changepsw = (RelativeLayout) view.findViewById(R.id.rl_changepsw);
        rl_changepsw.setOnClickListener(this);
        logout.setOnClickListener(this);
        view.findViewById(R.id.layout_top_back).setVisibility(View.GONE);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_logout:
                SharedPreferencesUtil.logout(getActivity());
                //解绑别名
                JPushInterface.setAlias(getActivity(), "", new TagAliasCallback() {

                    @Override
                    public void gotResult(int i, String s, Set<String> set) {
                        if (i == 0) {
                            //绑定成功
                            //保存状态值
                        } else {
                            //绑定失败
//                            showToast("设置推送失败，请重试");
                        }
                    }
                });
                SharedPreferencesUtil.setValue(getActivity(), SharedPreferencesUtil.ALIAS, "");
                startActivity(new Intent(getActivity(), LoginActivity.class));
                getActivity().finish();
                break;
            case R.id.rl_changepsw:
                startActivity(new Intent(getActivity(), ChangePasswordActivity.class));
                break;
        }
    }
}
